package main

import (
	"bytes"
	"fmt"
	"golang.org/x/crypto/ssh"
	"log"
	"os"
)

var v1=os.Args[1]

func main() {
	// 建立SSH客户端连接
	client, err := ssh.Dial("tcp", fmt.Sprintf("%s:22",v1), &ssh.ClientConfig{
		// 需要输入用户
		User:            "",
		// 需要输入密码
		Auth:            []ssh.AuthMethod{ssh.Password("")},
		HostKeyCallback: ssh.InsecureIgnoreHostKey(),
	})
	if err != nil {
		log.Fatalf("SSH dial error: %s", err.Error())
	}

	// 建立新会话
	session, err := client.NewSession()
	if err != nil {
		log.Fatalf("new session error: %s", err.Error())
	}

	defer session.Close()
	var str string
	for _, v := range os.Args[2:] {
		str = str + v + " "
	}
	var b bytes.Buffer
	session.Stdout = &b
	if err := session.Run(str); err != nil {
		panic("Failed to run: " + err.Error())
	}
	fmt.Println(b.String())
}
